<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('鉴定样本列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>

                        <input type="hidden" id="registerId" name="registerId" th:value="*{registerId}"/>
                        <input type="hidden" id="params[reportId]" name="params[reportId]" th:value="*{reportId}"/>
                        <input type="hidden" id="appraCon" name="appraCon" th:value="*{appraCon}"/>

                        <input type="hidden" name="params[isReport]" value="1"/>

                        <!--						<li>-->
                        <!--							<label>送鉴单位：</label>-->
                        <!--							<input type="text"  name="params[sendingUnit]"/>-->
                        <!--						</li>-->
                        <!--						<li>-->
                        <!--							<label>来文文号：</label>-->
                        <!--							<input type="text"  name="params[recordNumber]"/>-->
                        <!--						</li>-->
                        <li>
                            <label>样本名称：</label>
                            <input type="text" name="sampleName"/>
                        </li>

                        <!--						<li>-->
                        <!--							<label>样本ID：</label>-->
                        <!--							<input type="text" name="sampleId"/>-->
                        <!--						</li>-->
                        <!--						<li>-->
                        <!--							<label>样本类别：</label>-->
                        <!--							<select name="category" class=" noselect2 selectpicker" th:with="type=${@dict.getType('re_review_scope')}" data-none-selected-text="请选择审读范围" >-->
                        <!--								<option value="">所有</option>-->

                        <!--								<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>-->
                        <!--							</select>-->
                        <!--						</li>-->
                        <!--						<li>-->
                        <!--							<label>出版单位：</label>-->
                        <!--							<input type="text"  name="publishingUnit"/>-->
                        <!--						</li>-->
                        <!--						<li>-->
                        <!--							<label>审批状态：</label>-->
                        <!--							<select name="status">-->
                        <!--								<option value="">所有</option>-->
                        <!--								<option value="-1">代码生成请选择字典属性</option>-->
                        <!--							</select>-->
                        <!--						</li>-->
                        <!--						<li class="select-time">-->
                        <!--							<label>创建时间：</label>-->
                        <!--							<input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginTime]"/>-->
                        <!--							<span>-</span>-->
                        <!--							<input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endTime]"/>-->
                        <!--						</li>-->
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <!--		<div class="btn-group-sm" id="toolbar" role="group">-->
        <!--			<a class="btn btn-success" onclick="addTabAndRegisterId()" shiro:hasPermission="publish:identsample:add">-->
        <!--				<i class="fa fa-plus"></i> 添加-->
        <!--			</a>-->
        <!--			<a class="btn btn-primary single disabled" onclick="$.operate.editTab()" shiro:hasPermission="publish:identsample:edit">-->
        <!--				<i class="fa fa-edit"></i> 修改-->
        <!--			</a>-->
        <!--			<a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="publish:identsample:remove">-->
        <!--				<i class="fa fa-remove"></i> 删除-->
        <!--			</a>-->
        <!--			<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="publish:identsample:export">-->
        <!--				<i class="fa fa-download"></i> 导出-->
        <!--			</a>-->
        <!--		</div>-->
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('publish:identsample:edit')}]];
    var removeFlag = [[${@permission.hasPermi('publish:identsample:remove')}]];
    debugger
    var prefix = ctx + "publish/identsample";
    var _flag = $("#appraCon").val();
    var selectionIds = [];
    if (_flag == "false") {
        $(function () {
            var options = {
                url: prefix + "/listSampRegs",
                createUrl: prefix + "/add/{registerId}",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                sortName: "createTime",
                sortOrder: "desc",
                modalName: "鉴定样本",
                columns: [{
                radio: true,
                formatter:function(value,row,index){  //根据行里字段判断是否选中
                    var sampleId=getSampleId();
                    var sampleIds=sampleId.split(",");
                    for(var i in sampleIds) {
                        if(sampleIds[i]==row.id){
                            return {
                                checked : true//设置选中
                            };
                        }
                    }

                    return value;
                }
                },
                    {
                        field: 'id',
                        title: '编号',
                        visible: false
                    },
                    {
                        field: 'index',
                        align: 'center',
                        title: "序号",
                        formatter: function (value, row, index) {
                            var columnIndex = $.common.sprintf("<input type='hidden' name='index' value='%s'>", $.table.serialNumber(index));
                            return columnIndex + $.table.serialNumber(index);
                        }
                    },
                    {
                        field: 'sampleName',
                        title: '样本名称'
                    },
                    {
                        field: 'idAcceptRegister.sendUnit',
                        title: '送鉴单位'
                    },
                    {
                        field: 'idAcceptRegister.documentNum',
                        title: '来文文号'
                    },

                    {
                        field: 'sampleCode',
                        title: '样本ID'
                    },


                    {
                        field: 'createTime',
                        title: '样本录入日期'
                    },
                    {
                        field: 'sampleType',
                        title: '样本类别'
                    },

                    {
                        field: 'takeoverUser',
                        title: '接办人'
                    }

                ]
            };
            $.table.init(options);
        });
    } else {
        $(function () {
            var options = {
                url: prefix + "/listSampRegs",
                createUrl: prefix + "/add/{registerId}",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                sortName: "createTime",
                sortOrder: "desc",
                modalName: "鉴定样本",
                maintainSelected:true,
                rememberSelected:true,
                columns: [{
                    field: 'state',
                    checkbox:true,
                    formatter:function(value,row,index){  //根据行里字段判断是否选中

                        if ($.inArray(row.id, overAllIds) != -1) {
                            return {
                                // 存在则选中
                                checked: true
                            }
                        }

                        var sampleId=getSampleId();
                        var sampleIds=sampleId.split(",");
                        for(var i in sampleIds) {
                            if(sampleIds[i]==row.id){
                                return {
                                    checked : true//设置选中
                                };
                            }
                        }

                        return value;
                    }

                },
                    {
                        field: 'id',
                        title: '编号',
                        visible: false
                    },
                    {
                        field: 'index',
                        align: 'center',
                        title: "序号",
                        formatter: function (value, row, index) {
                            var columnIndex = $.common.sprintf("<input type='hidden' name='index' value='%s'>", $.table.serialNumber(index));
                            return columnIndex + $.table.serialNumber(index);
                        }
                    },
                    {
                        field: 'sampleName',
                        title: '样本名称'
                    },
                    {
                        field: 'idAcceptRegister.sendUnit',
                        title: '送鉴单位'
                    },
                    {
                        field: 'idAcceptRegister.documentNum',
                        title: '来文文号'
                    },

                    {
                        field: 'sampleCode',
                        title: '样本ID'
                    },


                    {
                        field: 'createTime',
                        title: '样本录入日期'
                    },
                    {
                        field: 'sampleType',
                        title: '样本类别'
                    },

                    {
                        field: 'takeoverUser',
                        title: '接办人'
                    }

                ]
            };
            $.table.init(options);
        });
    }






    // 全局数组,存放分页跳转时勾选的数据
    var overAllIds = new Array();
    var rowAll = new Array();
    $(function () {
        rowAll=parent.rows();
    })

    function examine(type, datas) {
        if(datas.length==0) {
            rowAll=[];
            return;
        }
        if (type.indexOf('uncheck') == -1) {
            $.each(datas, function(i, v) {
                // 添加时，判断一行或多行的 id 是否已经在数组里 不存则添加　
                overAllIds.indexOf(v.id) == -1 ? overAllIds.push(v.id) : -1;
                rowAll.indexOf(v) == -1 ? rowAll.push(v) : -1;

            });
        } else {
            $.each(datas, function (i, v) {
                // 删除取消选中行
                overAllIds.splice(overAllIds.indexOf(v.id), 1);
                rowAll.splice(rowAll.indexOf(v.id), 1);
            });
        }
    }

    $('#bootstrap-table').on('uncheck.bs.table check.bs.table check-all.bs.table uncheck-all.bs.table', function(e, rows) {
        // 点击时获取选中的行或取消选中的行
        var datas = $.isArray(rows) ? rows : [ rows ];

        // 保存到全局 Array() 里
        examine(e.type, datas);
    });


 


    /* 用户状态显示 */
    function statusTools(row) {
        if (row.isUse == '0') {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.id + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.id + '\')"></i> ';
        }
    }

    /* 是否启用-关闭 */
    function disable(id) {
        $.modal.confirm("确认要关闭吗？", function () {
            $.operate.post(prefix + "/changeStatus", {"id": id, "isUse": '0'});
        })
    }

    /* 是否启用-开启 */
    function enable(id) {
        $.modal.confirm("确认要开启吗？", function () {
            $.operate.post(prefix + "/changeStatus", {"id": id, "isUse": '1'});
        })
    }

    // 添加信息，以tab页展现
    function addTabAndRegisterId() {
        table.set();
        var id = $("#registerId").val();
        $.modal.openTab("添加" + table.options.modalName, addUrlAndRegisterId(id));
    }

    function addUrlAndRegisterId(id) {
        var url = $.common.isEmpty(id) ? table.options.createUrl.replace("{registerId}", "") : table.options.createUrl.replace("{registerId}", id);
        return url;
    }

    function getQueryVariable(variable)
    {
        var query = window.location.search.substring(1);
        var vars = query.split("&");
        for (var i=0;i<vars.length;i++) {
            var pair = vars[i].split("=");
            if(pair[0] == variable){return pair[1];}
        }
        return(false);
    }

    function getSampleId(){
        var sampleId=getQueryVariable("sampleId");
        return sampleId;


        /* var sampleIds=sampleId.split(",");
         for(var i in sampleIds) {
             console.log(sampleIds[i])
         }*/
    }




    /*-提交 */
    function submitHandler(index, layero) {
        // var rows = $.table.selectFirstColumns();
        if(_flag == "false"){
            var rows = $("#bootstrap-table").bootstrapTable('getSelections');
        }else{
            var rows = rowAll;
        }

        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        $.modal.close();
        // 父页面的方法
        // parent.selectUsers();
        parent.setSamnples(rows);

    }


</script>
</body>
</html>